/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2020年9月4日
 */
package com.massyframework.beanskin.runtime.service;

import com.massyframework.beanskin.Module;
import com.massyframework.beanskin.ModuleEvent;
import com.massyframework.beanskin.ModuleListener;
import com.massyframework.beanskin.framework.FrameworkDestroyingEvent;
import com.massyframework.beanskin.framework.FrameworkEvent;
import com.massyframework.beanskin.framework.FrameworkListener;
import com.massyframework.beanskin.ModuleDestoryingEvent;
import com.massyframework.beanskin.service.ServiceRepository;
import com.massyframework.beanskin.service.ServiceRepositoryFactory;



/**
 * 缺省的服务仓储工厂
 * 
 * @author huangkh
 *
 */
public class DefaultServiceRepositoryFactory implements ServiceRepositoryFactory, ModuleListener, FrameworkListener {
	
	private static ServiceAdmin INSTANCE;
	
	/**
	 * 
	 */
	public DefaultServiceRepositoryFactory() {
	}
	
	@Override
	public ServiceRepository getServiceRepository(Module<?> module) {
		if (INSTANCE == null) {
			synchronized(this) {
				if (INSTANCE == null) {
					INSTANCE = new ServiceAdmin();
				}
			}
		}
		return INSTANCE.getServiceRepository(module);
	}
	
	

	@Override
	public void onEvent(FrameworkEvent event) {
		if (event instanceof FrameworkDestroyingEvent) {
			
		}
	}

	@Override
	public void onEvent(ModuleEvent event) {
		if (event instanceof ModuleDestoryingEvent) {
			INSTANCE.onEvent((ModuleDestoryingEvent)event);
		}
		
	}
	
	
}
